/**
 * 
 */
package edu.uwm.nlp.jude.util;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import edu.uwm.nlp.jude.internal.NumberFullTextSpot;

/**
 * @author qing
 *
 * Jun 18, 2009
 */
public class Evaluation {
	
	public Evaluation()
	{
		
	}
	
	public void calSpotting(String path)
	{
		try {
			FileInputStream fis = new FileInputStream(path);
			DataInputStream in = new DataInputStream(fis);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String strLine;
			
			int total = 0;
			int correct = 0;
			int idCount = 0;
			while((strLine = br.readLine())!=null)
			{
				String[] fields = strLine.split("\t");
				if(fields.length == 2)
				{
					idCount = NumberFullTextSpot.checkField(fields[0]).size();
					if(fields[1].equals("y"))
						correct += idCount;
					total += idCount;
				}
			}
			System.out.println("---\n"+path+"\ngold spot="+total+", correct spot="+correct);
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void calSpotDir(String dir)
	{
		File dr = new File(dir);
		File[] files = dr.listFiles();
		for(int i=0; i<files.length; i++)
			calSpotting(files[i].getAbsolutePath());
	}
	
	public static void main(String[] args)
	{
		if(args.length != 1)
			System.out.println("--spot-result-dir");
		else
		{
			Evaluation evl = new Evaluation();
			evl.calSpotDir(args[0]);
		}
	}

}
